package com.plan.dao.service.card.impl;

import com.plan.base.constant.BaseCode;
import com.plan.base.exception.BizException;
import com.plan.controller.card.request.UpdateLotteryRateReq;
import com.plan.dao.mapper.card.PointPrizeDrawSettingMapper;
import com.plan.dao.service.card.PointPrizeDrawSettingDaoService;
import com.plan.entity.card.PointPrizeDrawSetting;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class PointPrizeDrawSettingDaoServiceImpl implements PointPrizeDrawSettingDaoService {
    @Resource
    private PointPrizeDrawSettingMapper pointPrizeDrawSettingMapper;

    @Override
    public PointPrizeDrawSetting getOneByTeamId(Long teamId) {
        return pointPrizeDrawSettingMapper.getOneByTeamId(teamId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int update(UpdateLotteryRateReq req) {
        PointPrizeDrawSetting update = new PointPrizeDrawSetting();
        update.setTeamId(req.getTeamId());
        update.setUpdaterId(req.getUpdateUserId());
        update.setSpendPoint(req.getSpendPoint());
        int num = pointPrizeDrawSettingMapper.updateByTeamId(update);
        if (num != 1) {
            throw new BizException(BaseCode.DATA_BE_MODIFIED);
        }
        return num;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insert(PointPrizeDrawSetting setting) {
        return pointPrizeDrawSettingMapper.insert(setting);
    }
}
